class Solution
{
public:
    vector<vector<int>> modifiedMatrix(vector<vector<int>> &matrix)
    {
        int m = matrix.size();
        int n = matrix[0].size();

        vector<int> colMax(n, -1);
        for (int i = 0; i < m; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                colMax[j] = max(colMax[j], matrix[i][j]);
            }
        }

        vector<vector<int>> answer(m, vector<int>(n));
        for (int i = 0; i < m; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                if (matrix[i][j] == -1)
                {
                    answer[i][j] = colMax[j];
                }
                else
                {
                    answer[i][j] = matrix[i][j];
                }
            }
        }
        return answer;
    }
};